const curry = (bindFun)=> {
  return function(firstArg){
    return function(secontArg){
      return bindFun(firstArg,secontArg)
    }
  }
}
const add = (x,y) => x + y
let curryAdd =  curry(add)(3)
const a = curryAdd(3)
a
const svg = (x,y) => (x + y) / 2
let currySvg = curry(svg)
let b =currySvg(4)(4)
b
const anyCurry = fn => {
  if(typeof fn !=='function'){
    throw Error('fn is not function')
  }
  return function curryiedFn(...args){
    // 判断...args传入的参数是否小于函数fn传入的参数，如果是，则通过apply递归调用curryiedFn函数
    if(args.length < fn.length){
      return function(){
        console.log(arguments)
        return curryiedFn.apply(null,args.concat([].slice.call(arguments)))
      }
    }
    // 当...args传入的参数和fn函数的参数相等时，执行完整函数结果
    return fn.apply(null,args)
  }
}
const func1 = (x,y,z) => x*y*z
let test1 = anyCurry(func1)(2)(6)(3)
test1
let test2 = anyCurry(add)(34)(34)
test2
const t = 'aagafga8ggf'.match(/[0-9]+/)
t

const logHepler = (mode,initMsg,errMsg,lineNum) => {
  if( mode === 'DEBUG'){
    console.log(initMsg,errMsg,lineNum)
  }
  if( mode === 'ERROR'){
    console.log(initMsg,errMsg,lineNum)
  }
  if( mode === 'WRAN'){
    console.log(initMsg,errMsg,lineNum)
  }
}
let debugLog = anyCurry(logHepler)('DEBUG')("debug.status.js")
let wranLog = anyCurry(logHepler)('WRAN')('wran.status.js')
let errorLog =anyCurry(logHepler)('ERROR')('error.status.js')
debugLog('debug.errorMsg',34)
wranLog('wran.msg',45)
errorLog('errorMsg')(443)


const partial = (fn, ...args)=>{
  console.log(args)

  let _args = args
  return function(...fullArgs){
    console.log(...fullArgs,fullArgs.length)

    let arg = 0
    for(let i = 0; i< _args.length && arg < fullArgs.length;i++){
      console.log(i,_args[i])

      if(_args[i] === undefined){
        console.log(fullArgs[arg])
        _args[i] = fullArgs[arg++]
      }
      console.log(_args)

      return fn.apply(null,_args)
    }
  }
}
let delayTenMs = partial(setInterval,undefined,10000)
delayTenMs(()=>console.log(12312))

const compose = (a,b) => c => a(b(c))
const fn1 = x => x * 2
const fn2 = y => y + 3
let tryfn = compose(fn1,fn2)
const ass = tryfn(4)
ass
